<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
    </el-row>

    <el-table :data="dataList" style="width: 100%">
      <el-table-column type="expand" label="展开/折叠" width="100">
        <template slot-scope="props">
          <el-table :data="props.row.subPlanList" style="width: 100%; margin-bottom: 20px">
            <el-table-column prop="cycleNo" label="期数" align="center" />
            <el-table-column prop="numberOfMonthlyInspectionTasks" label="月任务" align="center" />
            <el-table-column prop="numberOfQuarterlyInspectionTasks" label="季任务" align="center" />
            <el-table-column prop="numberOfSemiAnnualInspectionTasks" label="半年任务" align="center" />
            <el-table-column prop="numberOfAnnualInspectionTasks" label="年任务" align="center" />
            <el-table-column prop="numberOfBienniallyInspectionTasks" label="两年任务" align="center" />
            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button type="primary" icon="el-icon-view" size="mini" @click="handleDetail(scope.row)"
                  style="background: #999; border: none">详情查看</el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </el-table-column>
      <el-table-column prop="projectName" label="项目名称" align="center" />
      <el-table-column prop="completionPeriod" label="已完成期数" align="center" />
      <el-table-column prop="beginTime" label="开始时间" align="center" />
      <el-table-column prop="endTime" label="结束时间" align="center" />
      <!-- <el-table-column prop="endTime" label="项目负责人" align="center" />
      <el-table-column prop="endTime" label="一消工程师" align="center" />
      <el-table-column prop="endTime" label="操作员" align="center" />
      <el-table-column prop="endTime" label="批准人" align="center" /> -->
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { getRecordListDetails, exPortPlanList } from "@/api/plan-produce/task";
import { blobValidate } from "@/utils/ruoyi";

export default {
  name: "Building",
  data() {
    return {
      loading: false, // 遮罩层
      total: 0, // 总条数
      dataList: [], // 列表数据
      // 查询参数
      queryParams: {
        customerId: null,
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  created() {
    this.queryParams.customerId = this.$route.query.customerId;
    this.getList();
  },

  methods: {
    getList() {
      this.loading = true;
      getRecordListDetails(this.queryParams)
        .then((res) => {
          this.dataList = res.rows;
          this.total = res.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 导出按钮操作 */
    handleExport() {
      exPortPlanList({
        customerId: this.queryParams.customerId,
        projectId: this.queryParams.projectId,
      }).then(async (data) => {
        const isBlob = blobValidate(data);
        const filename = ` task_${new Date().getTime()}.xlsx`;
        if (isBlob) {
          saveAs(data.data, filename);
        } else {
          const resText = await data.text();
          const rspObj = JSON.parse(resText);
          const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode["default"];
          this.$modal.msgError(errMsg);
        }
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.dataList = [];
      this.handleQuery();
    },
    // 跳转详情
    handleDetail(row) {
      this.$router.push({
        path: "/contract/maintenanceDetail",
        query: {
          id: row.id,
          customerId: this.queryParams.customerId,
        },
      });
    },
  },
};
</script>
<style lang="scss" scoped></style>
